package japidviews._tags;
import java.util.*;
import java.io.*;
import cn.bran.japid.tags.Each;
import models.Recipe;
import models.Ingredient.Unit;
import java.text.SimpleDateFormat;
import play.modules.gae.GAE;
import static play.templates.JavaExtensions.*;
import static cn.bran.play.JapidPlayAdapter.*;
import static play.data.validation.Validation.*;
import japidviews._layouts.*;
import play.i18n.Messages;
import play.data.validation.Validation;
import play.mvc.Scope.*;
import models.*;
import play.data.validation.Error;
import play.i18n.Lang;
import japidviews._tags.*;
import play.mvc.Http.*;
import controllers.*;
import japidviews._javatags.*;
//
// NOTE: This file was generated from: japidviews/_tags/viewRecipe.html
// Change to this file will be lost next time the template file is compiled.
//
@cn.bran.play.NoEnhance
public class viewRecipe extends cn.bran.play.JapidTemplateBase
{
	public static final String sourceTemplate = "japidviews/_tags/viewRecipe.html";
	{
		putHeader("Content-Type", "text/html; charset=utf-8");
		setContentType("text/html; charset=utf-8");
	}

// - add implicit fields with Play

	final Request request = Request.current(); 
	final Response response = Response.current(); 
	final Session session = Session.current();
	final RenderArgs renderArgs = RenderArgs.current();
	final Params params = Params.current();
	final Validation validation = Validation.current();
	final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(validation);
	final play.Play _play = new play.Play(); 

// - end of implicit fields with Play 


	public viewRecipe() {
		super(null);
	}
	public viewRecipe(StringBuilder out) {
		super(out);
	}
/* based on https://github.com/branaway/Japid/issues/12
 */
	public static final String[] argNames = new String[] {/* args of the template*/"display", "recipe",  };
	public static final String[] argTypes = new String[] {/* arg types of the template*/"String", "Recipe",  };
	public static final Object[] argDefaults= new Object[] {null,null, };
	public static java.lang.reflect.Method renderMethod = getRenderMethod(japidviews._tags.viewRecipe.class);

	{
		setRenderMethod(renderMethod);
		setArgNames(argNames);
		setArgTypes(argTypes);
		setArgDefaults(argDefaults);
		setSourceTemplate(sourceTemplate);
	}
////// end of named args stuff

	private String display; // line 5
	private Recipe recipe; // line 5
	public cn.bran.japid.template.RenderResult render(String display,Recipe recipe) {
		this.display = display;
		this.recipe = recipe;
		long t = -1;
		try {super.layout();} catch (RuntimeException e) { super.handleException(e);} // line 5
		return new cn.bran.japid.template.RenderResultPartial(getHeaders(), getOut(), t, actionRunners, sourceTemplate);
	}
	@Override protected void doLayout() {
		beginDoLayout(sourceTemplate);
//------
;// line 1
if(asBoolean(display.equals("details"))) {// line 6
		p(" <article class=\"details\" itemscope itemtype=\"http://schema.org/Recipe\">\n" + 
" 	<div class=\"");// line 6
		if (recipe.image2 != null){// line 8
		p("recipeImgTwo");// line 8
		}else{// line 8
		p("recipeImg");// line 8
		}// line 8
		p("\">\n" + 
"		<a href=\"");// line 8
		p(lookup("Application.recipeImage", recipe.code));// line 9
		p("\"><img itemprop=\"image\"\n" + 
"			src=\"");// line 9
		p(lookup("Application.recipeThumb", recipe.code));// line 10
		p("\" alt=\"");// line 10
		p(recipe.name);// line 10
		p("\" title=\"");// line 10
		p(recipe.name);// line 10
		p("\"/></a>\n" + 
"		");// line 10
		if (recipe.image2 != null) {// line 11
		p("		<a href=\"");// line 11
		p(lookup("Application.recipeImage2", recipe.code));// line 12
		p("\"><img itemprop=\"image\"\n" + 
"			src=\"");// line 12
		p(lookup("Application.recipeThumb2", recipe.code));// line 13
		p("\" alt=\"");// line 13
		p(recipe.name);// line 13
		p("\" title=\"");// line 13
		p(recipe.name);// line 13
		p("\"/></a>\n" + 
"		");// line 13
		}// line 14
		p(" 	</div>\n" + 
" 	<h3 itemprop=\"name\">");// line 14
		p(recipe.name);// line 16
		p("</h3>\n" + 
" 	Ингредиенты:\n" + 
" 	<table class=\"ingredients table\">\n" + 
" 		");// line 16
		for(Ingredient ingredient: recipe.ingredients.order("unit").fetch()) {// line 19
		p(" 			");// line 19
		ingredient.product.get();// line 20
		p("		<tr>\n" + 
"			<td itemprop=\"ingredients\">");// line 20
		p(ingredient.product.name);// line 22
		p("</td>\n" + 
"			");// line 22
		if (ingredient.unit != Unit.NONE){// line 23
		p("<td>");// line 23
		final count _count0 = new count(getOut()); _count0.setActionRunners(getActionRunners()).setOut(getOut()); _count0.render(ingredient.count,ingredient.unit); // line 23// line 23
		p("</td>");// line 23
		}// line 23
		p("\n" + 
"		</tr>\n" + 
" 		");// line 23
		}// line 25
		p(" 	</table>\n" + 
" 	<br class=\"clear\"/>\n" + 
" 	<a class=\"backToRecipesLink\" href=\"");// line 25
		p(lookup("Application.recipes", new Object[]{}));// line 28
		p("\">&larr; Назад к списку</a> \n" + 
" 	<br class=\"clear\" /> <br class=\"clear\" />\n" + 
" 	<div class=\"recipeDescription\" itemprop=\"recipeInstructions\">");// line 28
		p(recipe.description);// line 30
		p("</div>\n" + 
" 	\n" + 
" 	");// line 30
		List<RecipeComment> comments = recipe.comments.fetch();// line 32
		p("\n" + 
" 	<h4 id=\"comments\">\n" + 
" 	");// line 32
		if (comments.size() > 0){// line 34
		p("Комментарии к рецепту '");// line 34
		p(recipe.name);// line 34
		p("': ");// line 34
		}else{// line 34
		p("Комментариев к рецепту '");// line 34
		p(recipe.name);// line 34
		p("' пока нет.");// line 34
		}// line 34
		p("\n" + 
" 	</h4>\n" + 
" 	");// line 34
		SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");// line 36
		p("\n" + 
" 	");// line 36
		for(RecipeComment comment: comments){// line 37
		p("		<div class=\"comment well\">\n" + 
"			<div class=\"comment-metadata\">\n" + 
"				<span class=\"comment-author\">");// line 37
		p(comment.name);// line 40
		p(",</span> <span\n" + 
"					class=\"comment-date\">");// line 40
		p(formatter.format(comment.dateCreated));// line 41
		p("</span>\n" + 
"			</div>\n" + 
"			<div class=\"comment-content\">");// line 41
		p(escape(comment.comment));// line 43
		p("</div>\n" + 
"		</div>\n" + 
" 	");// line 43
		}// line 45
		p(" 	\n" + 
" 	");// line 45
		if (GAE.isLoggedIn()) {// line 47
		p("	 	<input id=\"open-comment-form-btn\" type=\"button\" class=\"btn btn-primary\" onclick='javascript:$(\"#comment-form\").show();$(this).animate({\"opacity\":\"0\"},200, function(){$(\"#comment-form\").animate({\"opacity\":\"1\"}, 200)});' value=\"Оставить комментарий\"/>\n" + 
"	 	<form action=\"");// line 47
		p(lookup("Application.addRecipeComment", new Object[]{}));// line 49
		p("\" method=\"post\" accept-charset=\"utf-8\" enctype=\"application/x-www-form-urlencoded\" class=\"form-horizontal\" id=\"comment-form\">\n" + 
"	 		");// line 49
		p(authenticityToken());// line 50
		p("\n" + 
"	 		<input type=\"hidden\" name=\"id\" value=\"");// line 50
		p(recipe.id);// line 51
		p("\"/>\n" + 
"			<fieldset>\n" + 
"				<legend>Комментировать рецепт:</legend>\n" + 
"				<div class=\"control-group\">\n" + 
"					<label class=\"control-label\" for=\"name\">Имя:</label>\n" + 
"					<div class=\"controls\">\n" + 
"						<input type=\"text\" name=\"name\" value=\"");// line 51
		p(GAE.getUser());// line 57
		p("\" class=\"input-xlarge\" disabled=\"true\"/>\n" + 
"					</div>\n" + 
"				</div>\n" + 
"				<div class=\"control-group\">\n" + 
"					<label class=\"control-label\" for=\"comment\">Комментарий:</label>\n" + 
"					<div class=\"controls\">\n" + 
"						<textarea rows=\"10\" cols=\"20\" class=\"input-xlarge\" name=\"comment\">");// line 57
		p(flash("comment"));// line 63
		p("</textarea>\n" + 
"						<p class=\"help-block\">Обязательное</p>\n" + 
"						");// line 63
		if (hasError("comment")){// line 65
		p("<span class=\"alert-message error\">");// line 65
		error("comment");// line 65
		p("</span>");// line 65
		}// line 65
		p("\n" + 
"					</div>\n" + 
"				</div>\n" + 
"			</fieldset>\n" + 
"			<div class=\"form-actions\">\n" + 
"				<input type=\"submit\" class=\"btn btn-primary\" value=\"Комментировать\"/>\n" + 
"				<input type=\"button\" class=\"btn\" value=\"Отменить\" onclick=\"javascript:$('#comment-form').animate({'opacity':'0'}, 400, function(){$('#comment-form').hide();$('#open-comment-form-btn').animate({'opacity':'1'}, 400);});\"/>\n" + 
"			</div>\n" + 
" 		</form>\n" + 
" 	");// line 65
		} else {// line 74
		p(" 		<a href=\"");// line 74
		p(lookup("Application.login", request.action, recipe.code));// line 75
		p("\">Авторизуйтесь</a> чтобы комментировать.\n" + 
" 	");// line 75
		}// line 76
		p(" </article>\n");// line 76
		} else {// line 78
		p("	<article class=\"list\" itemscope itemtype=\"http://schema.org/Recipe\">\n" + 
"		<div class=\"recipeImg\">\n" + 
"			<a href=\"");// line 78
		p(lookup("Application.viewRecipeByCode", recipe.code));// line 81
		p("\"><img itemprop=\"image\"\n" + 
"				src=\"");// line 81
		p(lookup("Application.recipeThumb", recipe.code));// line 82
		p("\" alt=\"");// line 82
		p(recipe.name);// line 82
		p("\" title=\"");// line 82
		p(recipe.name);// line 82
		p("\"/></a>\n" + 
"		</div>\n" + 
"		<div class=\"ingredient-desc\">\n" + 
"			<h3 itemprop=\"name\"><a href=\"");// line 82
		p(lookup("Application.viewRecipeByCode", recipe.code));// line 85
		p("\">");// line 85
		p(recipe.name);// line 85
		p("</a></h3>\n" + 
"				Ингредиенты:\n" + 
"				<ul class=\"ingredients-small\">\n" + 
"				");// line 85
		final List<Ingredient> ingredients = recipe.ingredients.fetch();// line 88
		p("\n" + 
"				");// line 88
		final Each _Each1 = new Each(getOut()); _Each1.setOut(getOut()); _Each1.render(// line 89
ingredients, new Each.DoBody<Ingredient>(){ // line 89
public void render(final Ingredient ingredient, final int _size, final int _index, final boolean _isOdd, final String _parity, final boolean _isFirst, final boolean _isLast) { // line 89
// line 89
		p("					");// line 89
		ingredient.product.get();// line 90
		p("\n" + 
"					");// line 90
		if (_index < 3 || ingredients.size() == 3) {// line 91
		p("						<li itemprop=\"ingredients\">");// line 91
		p(ingredient.product.name);// line 92
		p("</li>\n" + 
"					");// line 92
		} else if (_index == 3){// line 93
		p("						<li>...</li>\n" + 
"					");// line 93
		}// line 95
		p("				");// line 95
		
}

StringBuilder oriBuffer;
@Override
public void setBuffer(StringBuilder sb) {
	oriBuffer = getOut();
	setOut(sb);
}

@Override
public void resetBuffer() {
	setOut(oriBuffer);
}

}
);// line 89
		p("				</ul>\n" + 
"				");// line 96
		List<RecipeComment> comments = recipe.comments.fetch();// line 98
		p("\n" + 
"				<span><a href=\"");// line 98
		p(lookup("Application.viewRecipeByCode", recipe.code));// line 99
		p("#comments\">");// line 99
		if (comments.size() > 0){// line 99
		p("Комментариев: ");// line 99
		p(comments.size());// line 99
		;// line 99
		}else{// line 99
		p("Комментировать рецепт");// line 99
		}// line 99
		p("</a></span>\n" + 
"		</div>\n" + 
"	</article>\n");// line 99
		}// line 102
		
		endDoLayout(sourceTemplate);
	}

}